package com.sskj.phoenixcoin.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.phoenixcoin.activity.AppSetTpwdActivity;
import com.sskj.phoenixcoin.bean.AppBanlance;
import com.sskj.phoenixcoin.http.HttpConfig;


public class AppSetTpwdActivityPresenter extends BasePresenter<AppSetTpwdActivity> {

    // 更新交易密码
    public void updateTpwd(String id, String phoenixTradePswd, String tel, String code) {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.TPWDUPDATE)
                .params("systemType", "ANDROID")
                .params("id", id)
                .params("phoenixTradePswd", MD5Util.getMd5Value(phoenixTradePswd))
                .params("tel", tel)
                .params("code", code)
                .tag(this)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.setTpwdOK();
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }
                    }
                });
    }

    // 获取短信验证码
    public void getCode(String tel, String type) {
        OkGo.<HttpData<String>>get("http://110754.com" + HttpConfig.GETCODE)
                .params("systemType", "ANDROID")
                .params("tel", tel)
                .params("codeType", type)
                .tag(this)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.requestCodeSuccess();
                        }
                    }
                });
    }
}
